<template>
	<view class="index">
		<!-- 头部状态栏静态组件 showIcon标识：主页不显示icon -->
		<musicHead title="网易云音乐" :showIcon="false" textHeadColor="#000"></musicHead>
		<!-- 骨架屏：加载页面的时候，数据还未获取到时，先加载骨架屏，增加体验 -->
		<view v-if="isLoading">
			<m-for-skeleton :avatarSize="200" :row="3" :loading="isLoading" isarc="square" v-for="(item,key) in 4"
				:titleStyle="{}" :key="key" :title="false">
			</m-for-skeleton>
		</view>
		<!-- container容器是公共的容器，因为头部状态栏是固定的，使用scroll-view让其下面的部分滚动，而头部状态栏不滚动 -->
		<view class="container" v-else>
			<scroll-view scroll-y="true">
				<!-- 搜索框 -->
				<view class="search" @click="handleToSearch">
					<text class="iconfont icon-Magnifier"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<!-- 各种榜单 -->
				<view class="list">
					<view class="list-item" v-for="item in toplist" :key="item.id" @click="handleToList(item.id)">
						<view class="img">
							<image :src="item.coverImgUrl"></image>
							<text>{{item.updateFrequency}}</text>
						</view>
						<view class="songs">
							<view class="app-text-ellipsis" v-for="(item2,index) in item.tracks">{{index+1}} . {{item2.first}} - {{item2.second}}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		toplistDetail
	} from '../../common/api.js'
	// 引入骨架屏
	import mForSkeleton from "@/components/m-for-skeleton/m-for-skeleton"
	export default {
		data() {
			return {
				// title: '网易云音乐',
				// // 首页不显示头部状态栏返回主页图标
				// showIcon:false,
				// 保存榜单数据
				toplist: [],
				// 骨架屏是否展示
				isLoading: true
			}
		},
		components: {
			mForSkeleton
		},
		onLoad() {
			toplistDetail().then(({
				data
			}) => {
				// console.log(data)
				setTimeout(() => {
					// 只要前四项
					data.list.length = 4
					this.toplist = data.list

					// 隐藏骨架屏，显示内容
					this.isLoading = false
				}, 1000)
			})
		},
		methods: {
			// 跳转歌曲列表页
			handleToList(id) {
				uni.navigateTo({
					url: `/pages/list/list?id=${id}`
				})
			},
			// 跳转搜索页
			handleToSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		.search {
			// width: 100%;
			display: flex;
			align-items: center;
			height: 70rpx;
			background-color: #f7f7f7;
			border-radius: 50rpx;
			margin: 0 34rpx;

			text {
				margin: 0 20rpx 0 10rpx;
			}

			input {
				font-size: 28rpx;
			}
		}
	}

	.list {
		margin: 30rpx 34rpx;

		.list-item {
			display: flex;
			width: 100%;
			height: 212rpx;
			margin-bottom: 30rpx;
			.img {
				width: 212rpx;
				height: 212rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}

				text {
					position: absolute;
					bottom: 4rpx;
					left: 10rpx;
					color: #fff;
					font-size: 24rpx;
				}
			}

			.songs {
				box-sizing: border-box;
				padding: 26rpx 22rpx;
				width: 470rpx;
				height: 470rpx;
				line-height: 58rpx;
				font-size: 24rpx;

				view {
					// overflow: hidden; //超出的文本隐藏
					// text-overflow: ellipsis; //溢出用省略号显示
					// white-space: nowrap; //溢出不换行
					width: 380rpx;
				}
			}
		}
	}
</style>
